﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace BanHangCshap.Class
{
    class DonViTinh:Database
    {
        private int _madvt;


        public int madvt
        {
            set { _madvt = value; }
            get { return _madvt; }
        }
        private string _tendvt;
        public string tendvt
        {
            set { _tendvt = value; }
            get { return _tendvt; }
        }
        private string _ghichudvt;
        public string ghichudvt
        {
            set { _ghichudvt = value; }
            get { return _ghichudvt; }
        }
        public DonViTinh() { }

        public DonViTinh(int madvt)
        {
            string sql = "select * from DonViTinh where madvt = " + madvt + "";
            foreach (DataRow dr in getDataTable(sql).Rows)
            {
                this.madvt = madvt;
                this.tendvt = dr["tendvt"].ToString().Trim();
                this.ghichudvt = dr["ghichudvt"].ToString().Trim();
            }
        }
        public Boolean isExistDonViTinh(string tendvt)
        {
            string sql = "select *  from DonViTinh where tendvt = N'" + tendvt + "'";
            return isExist(sql);
        }
        public DataTable layDSDonViTinh()
        {
            string sql = "select * from DonViTinh";
            return getDataTable(sql);
        }
        public Boolean themDonViTinh()
        {
            string sql = "insert into DonViTinh(tendvt,ghichudvt) values (N'" + tendvt + "',N'" + ghichudvt + "')";
            return executeQuery(sql);
        }
        public Boolean suaDonViTinh(int madvt)
        {
            string sql = "update DonViTinh set tendvt =N'" + tendvt + "', ghichudvt = N'" + ghichudvt + "' where madvt = " + madvt + "";
            return executeQuery(sql);
        }
        public Boolean xoaDonViTinh(int madvt)
        {
            string sql = "delete DonViTinh where madvt = " + madvt + "";
            return executeQuery(sql);
        }

    }
}
